package com.walk.logcat;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.walk.logcatlibrary.R;

public class AppDataActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.data_activity);
        findViewById(R.id.log).setOnClickListener(v -> {

            Intent intent = new Intent(this, LogcatActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        });

        TextView textView = findViewById(R.id.text_data);

        String  appData ="版本名 :"+getAppVersionName()+"\n"+"版本号 :"+getAppVersionCode()+"\n";
        appData = appData+AppDataContent.appData;
        textView.setText(appData);

    }


    private String getAppVersionName(){
        String AppVersionName = "Unknown";
        try {
            AppVersionName =  getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }

        return AppVersionName;

    }

    private String getAppVersionCode(){

        String AppVersionCode = "Unknown";
        try {
            AppVersionCode =  getPackageManager().getPackageInfo(getPackageName(), 0).versionCode+"";
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }

        return AppVersionCode;

    }
}
